#include <gtest/gtest.h>
#include "thrdpool.hpp"


class ThrdPoolTest : public ::testing::Test {
  protected:
    void SetUp() override {
    }

    void TearDown() override { }
};


TEST_F(ThrdPoolTest, ThrdPoolTestRunTaskCheck)
{
    sl::ThrdPool pool(8);
    int task_num = 1000;

    std::vector<std::future<int>> futures;
    for (int i = 0; i < task_num; ++i) {
        futures.emplace_back(pool.submit([i]() {
            return 1;
        }));
    }

    int sum = 0;
    for (auto& fut : futures) {
        sum += fut.get();
    }

    ASSERT_EQ(sum, task_num);
}

TEST_F(ThrdPoolTest, ThrdPoolTestRunTaskCheckCurrent)
{
    sl::ThrdPool pool;
    int task_num = 10000;

    std::vector<std::future<int>> futures;
    for (int i = 0; i < task_num; ++i) {
        futures.emplace_back(pool.submit([i]() {
            return 1;
        }));
    }

    int sum = 0;
    for (auto& fut : futures) {
        sum += fut.get();
    }

    ASSERT_EQ(sum, task_num);
}